for _ in range(int(input())):
N = int(input())
A = list(map(int, input().split(" ")))
S = sum(A)
print((S%N)*(N-(S%N)))
#include <bits/stdc++.h>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
#define fast cin.tie(0); cin.sync_with_stdio(0);
#define ll long long
#define ull unsigned long long
#define ld long double
#define oo (ll)1e9
#define OO (ll)1e18
#define PI acos(-1)
#define LL __int128
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>,rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;
const int MOD = 998244353;
const ld eps = 1e-6;
int tt = 1;
int test;
const int N = 2e5 + 5;
ll a[N];
int n;
void solve()
{
cin >> n;
ll sum = 0;
for(int i = 0 ; i < n ; i++) cin >> a[i] , sum += a[i];
ll rem = sum % n;
cout << rem * (n - rem) << '\n';
}
int main()
{
fast
cin >> tt;
while(tt--)
solve();
return 0;
}
46A - Ball Game | 114A - Cifera |
776A - A Serial Killer | 25B - Phone numbers |
1633C - Kill the Monster | 1611A - Make Even |
1030B - Vasya and Cornfield | 1631A - Min Max Swap |
1296B - Food Buying | 133A - HQ9+ |
1650D - Twist the Permutation | 1209A - Paint the Numbers |
1234A - Equalize Prices Again | 1613A - Long Comparison |
1624B - Make AP | 660B - Seating On Bus |
405A - Gravity Flip | 499B - Lecture |
709A - Juicer | 1358C - Celex Update |
1466B - Last minute enhancements | 450B - Jzzhu and Sequences |
1582C - Grandma Capa Knits a Scarf | 492A - Vanya and Cubes |
217A - Ice Skating | 270A - Fancy Fence |
181A - Series of Crimes | 1638A - Reverse |
1654C - Alice and the Cake | 369A - Valera and Plates |